package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.BaseUser;
import com.briup.jz.bean.BaseUserExample;
import com.briup.jz.bean.extend.BaseUserExtend;
import com.briup.jz.service.BaseUserService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description = "角色权限")
@Validated
@RestController
@RequestMapping("/baseUser")
public class BaseUserController {
	@Autowired
	private BaseUserService basUserService;

	@ApiOperation(value = "查询所有用户信息")
	@GetMapping("query")
	public Message query(String name) {
		List<BaseUser> list = basUserService.query(name);
		return MessageUtil.success(list);
	}

	@ApiOperation(value = "通过id删除")
	@GetMapping("deleteById")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键", paramType = "query", required = true), })
	public Message deleteById(@NotNull Long id) {
		basUserService.deleteById(id);
		return MessageUtil.success("删除成功");
	}

	@ApiOperation(value = "保存或更新用户类信息")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键", paramType = "form"),
			@ApiImplicitParam(name = "username", value = "用户名", paramType = "form", required = true),
			@ApiImplicitParam(name = "password", value = "密码", paramType = "form"),
			@ApiImplicitParam(name = "telephone", value = "电话号码", paramType = "form"),
			@ApiImplicitParam(name = "realname", value = "真实姓名", paramType = "form"),
			@ApiImplicitParam(name = "gender", value = "性别", paramType = "form"),
			@ApiImplicitParam(name = "birth", value = "生日", paramType = "form"),
			@ApiImplicitParam(name = "email", value = "邮箱", paramType = "form"),
			@ApiImplicitParam(name = "status", value = "地位", paramType = "form"),
			@ApiImplicitParam(name = "userFace", value = "用户人脸信息地址", paramType = "form"),
			@ApiImplicitParam(name = "registerTime", value = "注册时间", paramType = "form"),
			@ApiImplicitParam(name = "nation", value = "民族", paramType = "form"),
			@ApiImplicitParam(name = "idCard", value = "身份证号", paramType = "form"),
			@ApiImplicitParam(name = "idcardPhotoPositive", value = "身份证照片地址", paramType = "form"),
			@ApiImplicitParam(name = "idcardPhotoNegative", value = "失败的身份证地址", paramType = "form"),
			@ApiImplicitParam(name = "bankCard", value = "银行卡", paramType = "form"),
			@ApiImplicitParam(name = "bankCardPhoto", value = "银行卡照片地址", paramType = "form"),
			@ApiImplicitParam(name = "balance", value = "余额", paramType = "form"),
			@ApiImplicitParam(name = "certificationStatus", value = "实名认证状态", paramType = "form"),
			@ApiImplicitParam(name = "certificationTime", value = "认证时间", paramType = "form"), })
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(BaseUser baseUser) {
		basUserService.saveOrUpdate(baseUser);
		return MessageUtil.success("更新成功");
	}

	@GetMapping("selectUserRole")
	@ApiOperation(value = "级联查询用户及角色")
	@ApiImplicitParams({ @ApiImplicitParam(name = "userName", value = "用户名", paramType = "query"),
			@ApiImplicitParam(name = "status", value = "状态[正常,禁用]", paramType = "query"),
			@ApiImplicitParam(name = "roleName", value = "角色名", paramType = "query"), })
	public Message selectUserRole(String userName, String status, String roleName) {
		List<BaseUserExtend> list = basUserService.selectUserRole(userName, status, roleName);
		return MessageUtil.success(list);
	}

	@GetMapping("selectAllStatus")
	@ApiOperation(value = "查询状态")
	public Message selectAllStatus() {
		List<BaseUser> list = basUserService.selectAllStatus();
		return MessageUtil.success(list);
	}
	
	
	
}
